package custom_class;


import java.io.Serializable;

/**
 * 自定义数据类型，用于多样测试
 * @author wenyuan
 * @version 1.0
 * @date 2023/7/18
 * @since 8
 */
public class Person implements Serializable {

    /**
     * serialVersionUID的作用是兼容一些类内容的增加 如下
     * 1. Adding new variables to the class
     * 2. Changing the variables from transient to non-transient, for serialization it’s like having a new field.
     * 3. Changing the variable from static to non-static, for serialization it’s like having a new field.
     * 如果不指定，会自动生成一个，所以当类变化的时候，自动生成的版本会变，导致不能兼容
     * 如果由自己指定，就不会变化
     */
    // private static final long serialVersionUID = -299482035708790407L;

    private int height;
    private double weight;

    private int age;
    private String sex;
    private String name;

    public Person(){}

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Person(int height, double weight, int age, String sex) {
        this.height = height;
        this.weight = weight;
        this.age = age;
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "custom_class.Person{" +
                "height=" + height +
                "cm, weight=" + weight +
                "kg, age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object obj) {
        Person person = null;
        if(obj instanceof Person){
            person = (Person) obj;
        }
        return this.getAge() == person.getAge();
    }
}
